package com.task.web.controller.core;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.task.common.annotation.Log;
import com.task.common.core.controller.BaseController;
import com.task.common.core.domain.AjaxResult;
import com.task.common.core.page.TableDataInfo;
import com.task.common.enums.BusinessType;
import com.task.common.utils.SecurityUtils;
import com.task.core.dto.request.PluginPlatformRequestDTO;
import com.task.core.dto.request.PluginRequestDTO;
import com.task.core.service.CheckService;
import com.task.core.service.PluginPlatformService;
import com.task.core.service.PluginService;

import io.swagger.annotations.Api;

/**
 * @author 迪迦.
 * @date 2024/11/4 14:32
 */
@Api("")
@RestController
@RequestMapping("/pluginPlatform")
public class PluginPlatformController extends BaseController {


  @Resource
  private PluginPlatformService pluginPlatformService;

  @Resource
  private CheckService checkService;


  @PreAuthorize("@ss.hasPermi('pluginPlatform:list')")
  @GetMapping("/getPluginPlatformByPage")
  public TableDataInfo getPluginPlatformByPage(PluginPlatformRequestDTO request) {
    startPage(request.getPageNum(), request.getPageSize());
    return getDataTable(pluginPlatformService.getPluginPlatformByPage(request));
  }


  @PreAuthorize("@ss.hasPermi('pluginPlatform:option')")
  @GetMapping("/getPluginPlatformForOption")
  public TableDataInfo getPluginPlatformForOption(PluginPlatformRequestDTO request) {
    return getDataTable(pluginPlatformService.getPluginPlatformForOption(request));
  }

  @Log(title = "PluginPlatform管理", businessType = BusinessType.INSERT)
  @PostMapping("/addPluginPlatform")
  public AjaxResult addPluginPlatform(@Valid @RequestBody PluginPlatformRequestDTO request) {
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    pluginPlatformService.addPluginPlatform(request);
    return success();
  }

  @Log(title = "PluginPlatform管理", businessType = BusinessType.UPDATE)
  @PutMapping("/modifyPluginPlatform")
  public AjaxResult modifyPluginPlatform(@Valid @RequestBody PluginPlatformRequestDTO request) {
    checkService.check("data_plugin_platform", request.getCode());
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    pluginPlatformService.modifyPluginPlatform(request);
    return success();
  }

  @Log(title = "PluginPlatform管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/deletePluginPlatform/{pluginPlatformCode}")
  public AjaxResult deletePluginPlatform(@PathVariable String pluginPlatformCode) {
    checkService.check("data_plugin_platform", pluginPlatformCode);
    pluginPlatformService.deletePluginPlatform(pluginPlatformCode, SecurityUtils.getLoginUser().getUserId());
    return success();
  }

}
